package com.zhu.service;

import com.zhu.mapper.PersonMapper;
import com.zhu.pojo.Organization;
import com.zhu.pojo.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PersonService {
    @Autowired
    private PersonMapper personMapper;

    public List<Person> search(Person person){
        return personMapper.search(person.getName());
    }

    public void personadd(Person person){
        personMapper.personadd(person);
    }
    public Organization getlist(){
        Organization company = new Organization();
        company.setId(1);
        company.setName("公司");
        company.setList(personMapper.getlist(company.getId()));
        for(Organization o:company.getList()){
            //if(personMapper.getlist(o.getId())==null) break;
            o.setList(personMapper.getlist(o.getId()));
            for(Organization oo:o.getList()){
                oo.setList(personMapper.getlist(oo.getId()));
            }
        }
        return company;
    }

    public Person searchByName(String name){
        return personMapper.searchByName(name);
    }

    public void update(Person person){
        personMapper.update(person);
    }

    public Person searchOne(String account){
        return personMapper.searchOne(account);
    }

    public void delete(String account){
        personMapper.delete(account);
    }
}
